<?php
class Node{
	var $attrs = array();
	var $atidx = 0;
	
	public function setAttribute($attr, $value){
		if(array_key_exists($attr, $this->attrs)){
			return false;
		}else{
			$this->attrs[$attr] = $value;
			return true;
		}
	}

	public function addAttribute($attr, $value, $dilimiter){
		if(array_key_exists($attr, $this->attrs)){
			$v = $this->attrs[$attr].$dilimiter.$value;
			$this->attrs[$attr] = &$v;
		}else{
			$this->attrs[$attr] = $value;
		}
	}
	
	public function setAtAttribute($value){
		$ret = $this->setAttribute('@'.$this->atidx, $value);
		$this->atidx++;
		return $ret;
	}
	
	public function getAtAttributes(){
		$ret = array();
		for($i =0; $i <$this->atidx; ++$i){
			$ret []= $this->getAttribute('@'.$i);
		}
		return $ret;
	}
	
	public function getAttribute($attr){
		if(array_key_exists($attr, $this->attrs)){
			return $this->attrs[$attr];
		}else{
			return '';
		}
	}
	
	public function hasAttribute($attr){
		return array_key_exists($attr, $this->attrs);
	}
			
	public function addChild(Node $child){		
		if(array_key_exists('>', $this->attrs)){
			$this->attrs['>'] []= $child;
		}else{
			$this->attrs['>'] = array($child);
		}
	}
	
	public function isEmpty(){
		return count($this->attrs) == 0;
	}
	
	public function getChilds(){
		$ret = $this->getAttribute('>');
		if(NULL == $ret){
			return array();
		}else{
			return $ret;
		}
	}	
}